<?php

//134589
//134715

include( "./admin/include/func.php");
include( "./admin/include/thumb.php");

$db = new db();
if ( ! $db->connect()) exit( mysql_error());

//$db->sql = "DELETE FROM hirdetes WHERE azonosito NOT IN (SELECT azonosito FROM hird)";
//$db->query();

$db->sql = "SELECT max(azonosito) FROM hirdetes";
$db->query();
$rs = mysql_fetch_row( $db->rs);
$max = (int)$rs[0];
debug( $max);

$db->sql = "
INSERT INTO hirdetes (`id`, `azonosito`, `user_id`, `nev`, `email`, `telefon`, `targy`, `szoveg`, `kep`, `rovat`, `rovat_nev`, `ar`, `telepules`,
`regio`, `regio_nev`, `feladas`, `lejarat`, `weblap`, `aktiv`, `aktivkod`, `szponzoralt`, `lejartertesitve`, `lastmodified`) 
SELECT '0',`azonosito`, `userid`, `felado`, `email`,`telefon`, `targy`, `hirdszov`, `kep`, 0, `rovat`, `ar`, `varos`, 0, `regio`,
`feladas`, `lejarat`,  `http`, `aktiv`, `aktivkod`, `szponzor`, `lejart_ertesitve`, `feladas` FROM hird WHERE azonosito>$max";
$db->query();

$db->sql = "UPDATE hirdetes SET `order`=id";
$db->query();

/*
$db->sql = "SELECT h.azonosito,h.targy,h.lastmodified,i.feladas 
            FROM hirdetes h, hird i 
            WHERE h.azonosito=i.azonosito AND h.lastmodified<i.feladas";
$db->query();

$ups = array ();
while ($rs = mysql_fetch_assoc( $db->rs)) $ups[] = $rs;

foreach ($ups as $up) {
	debug( $up);
	$db->sql = "UPDATE hirdetes SET lastmodified='".$up['feladas']."' WHERE azonosito='".$up['azonosito']."'"; 
	$db->query();
}
*/
   
?>
